#include "cpoint3f.h"

CPoint3f::CPoint3f()
{
        this->Set(0.0, 0.0, 0.0);
}

CPoint3f::CPoint3f(double fX, double fY, double fZ)
{
        this->Set(fX, fY, fZ);
}

CPoint3f::CPoint3f(const CPoint3f & original)
{
        this->m_fX = original.m_fX;
        this->m_fY = original.m_fY;
        this->m_fZ = original.m_fZ;
}

CPoint3f::CPoint3f(const CVector3f & original)
{
    this->m_fX = original.m_fX;
    this->m_fY = original.m_fY;
    this->m_fZ = original.m_fZ;
}

void CPoint3f::Add(CPoint3f * pP)
{
        this->m_fX += pP->GetX();
        this->m_fY += pP->GetY();
        this->m_fZ += pP->GetZ();
}

void CPoint3f::Add(CPoint3f P)
{
        this->m_fX += P.GetX();
        this->m_fY += P.GetY();
        this->m_fZ += P.GetZ();
}

double CPoint3f::Distance(CPoint3f * pP)
{
        return this->Distance(*pP);
}

double CPoint3f::Distance(CPoint3f P)
{
        return sqrt(this->Distance2(P));
}

double CPoint3f::Distance2(CPoint3f * pP)
{
        return this->Distance2(*pP);
}

double CPoint3f::Distance2(CPoint3f P)
{
        double fA = this->GetX()-P.GetX();
        double fB = this->GetY()-P.GetY();
        double fC = this->GetZ()-P.GetZ();

        return pow(fA,2)+pow(fB,2)+pow(fC,2);
}

void CPoint3f::Div(double fVal)
{
        this->Set(this->GetX()/fVal, this->GetY()/fVal, this->GetZ()/fVal);
}

void CPoint3f::Mult(double fVal)
{
        this->Set(this->GetX()*fVal, this->GetY()*fVal, this->GetZ()*fVal);
}

void CPoint3f::SetX(double fX)
{
        this->m_fX = fX;
}

void CPoint3f::SetY(double fY)
{
        this->m_fY = fY;
}

void CPoint3f::SetZ(double fZ)
{
        this->m_fZ = fZ;
}

void CPoint3f::Set(double fX, double fY, double fZ)
{
        this->SetX(fX);
        this->SetY(fY);
        this->SetZ(fZ);
}

void CPoint3f::operator =(CPoint3f original)
{
        this->m_fX = original.GetX();
        this->m_fY = original.GetY();
        this->m_fZ = original.GetZ();
}

CPoint3f CPoint3f::crossProduct(CPoint3f P)
{
        CPoint3f PRes;
        PRes.Set((this->GetY()*P.GetZ())-(this->GetZ()*P.GetY()),
                         (this->GetZ()*P.GetX())-(this->GetX()*P.GetZ()),
                         (this->GetX()*P.GetY())-(this->GetY()*P.GetX()));
        return PRes;
}

void CPoint3f::normalize()
{
        double fNorm = sqrt(pow(this->GetX(),2.0) + pow(this->GetY(),2.0) + pow(this->GetZ(),2.0));
        this->Div(fNorm);
}

double CPoint3f::GetX()
{
        return this->m_fX;
}

double CPoint3f::GetY()
{
        return this->m_fY;
}

double CPoint3f::GetZ()
{
        return this->m_fZ;
}

bool CPoint3f::operator ==(CPoint3f P)
{
        if (this->m_fX == P.GetX() && this->m_fY == P.GetY() && this->m_fZ == P.GetZ())
                return true;
        return false;
}

bool CPoint3f::operator !=(CPoint3f P)
{
        return !this->operator ==(P);
}

void CPoint3f::operator+=(CPoint3f P)
{
    this->m_fX += P.GetX();
    this->m_fY += P.GetY();
    this->m_fZ += P.GetZ();
}

void CPoint3f::operator-=(CPoint3f P)
{
    this->m_fX -= P.GetX();
    this->m_fY -= P.GetY();
    this->m_fZ -= P.GetZ();
}

CPoint3f CPoint3f::operator +(CVector3f V)
{
    return CPoint3f(this->m_fX+V.m_fX, this->m_fY+V.m_fY, this->m_fZ+V.m_fZ);
}

CPoint3f CPoint3f::operator -(CVector3f V)
{
    return CPoint3f(this->m_fX-V.m_fX, this->m_fY-V.m_fY, this->m_fZ-V.m_fZ);
}

CVector3f CPoint3f::operator -(CPoint3f P)
{
    return CVector3f(this->GetX()-P.GetX(), this->GetY()-P.GetY(), this->GetZ()-P.GetZ());
}
